package com.ruoyi.card.controller;

import java.text.ParseException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.card.domain.vo.GetTimeListVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.card.domain.SillCard;
import com.ruoyi.card.service.ISillCardService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 员工打卡表Controller
 * 
 * @author ruoyi
 * @date 2024-08-12
 */
@RestController
@RequestMapping("/card/card")
public class SillCardController extends BaseController
{
    @Autowired
    private ISillCardService sillCardService;

    /**
     * 查询员工打卡表列表
     */
    @PreAuthorize("@ss.hasPermi('card:card:list')")
    @GetMapping("/list")
    public TableDataInfo list(SillCard sillCard)
    {
        startPage();
        List<SillCard> list = sillCardService.selectSillCardList(sillCard);
        return getDataTable(list);
    }
    /**
     * 查询员工打卡表打卡时间
     */

    @GetMapping("/time")
    public Boolean time()
    {
        startPage();
        Boolean aBoolean = sillCardService.selectTimeList();
        return aBoolean;
    }

    /**
     * 导出员工打卡表列表
     */
    @PreAuthorize("@ss.hasPermi('card:card:export')")
    @Log(title = "员工打卡表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SillCard sillCard)
    {
        List<SillCard> list = sillCardService.selectSillCardList(sillCard);
        ExcelUtil<SillCard> util = new ExcelUtil<SillCard>(SillCard.class);
        util.exportExcel(response, list, "员工打卡表数据");
    }

    /**
     * 获取员工打卡表详细信息
     */
    @PreAuthorize("@ss.hasPermi('card:card:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sillCardService.selectSillCardById(id));
    }

    /**
     * 新增员工打卡表
     */
    @PreAuthorize("@ss.hasPermi('card:card:add')")
    @Log(title = "员工打卡表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SillCard sillCard)
    {
        return toAjax(sillCardService.insertSillCard(sillCard));
    }

    /**
     * 新增员工打卡表
     */
    @PreAuthorize("@ss.hasPermi('card:card:add')")
    @Log(title = "员工打卡表", businessType = BusinessType.INSERT)
    @PostMapping("/dk")
    public AjaxResult addDK() throws ParseException {
        return toAjax(sillCardService.insertDK());
    }

    /**
     * 修改员工打卡表
     */
    @PreAuthorize("@ss.hasPermi('card:card:edit')")
    @Log(title = "员工打卡表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SillCard sillCard)
    {
        return toAjax(sillCardService.updateSillCard(sillCard));
    }

    /**
     * 删除员工打卡表
     */
    @PreAuthorize("@ss.hasPermi('card:card:remove')")
    @Log(title = "员工打卡表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sillCardService.deleteSillCardByIds(ids));
    }
}
